
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>1101_高阶函数-函数柯里化</title>
</head>

<body>
  <div id="test"></div>
  <!-- react核心库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <!-- 用于支持react操作DOM -->
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 用于将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>

  <script type="text/babel">

    // 1.创建组件
    class Login extends React.Component {
      // 初始化状态
      state = {
        username: '', // 用户名
        password: '' // 密码
      }
      // 保存表单数据
      saveFormData = (type) => {
        return (e) => this.setState({[type]: e.target.value})
      }

      // 表单提交回调
      handleSubmit = (event) => {
        event.preventDefault();
        const {username, password} = this.state
        alert(`用户名：${username} 密码：${password}`)
      }
      render() {

        return (
          <form action="http://www.gaogzhen.com" onSubmit={this.handleSubmit}>
            用户名：<input type="text" name="username" placeholder="请输入用户名" onChange={this.saveFormData('username')}/><br/>
            密&nbsp;&nbsp;&nbsp;码：<input type="text" name="password" placeholder="请输入密码" onChange={this.saveFormData('password')}/><br/>
            <button>登陆</button><br />
          </form>
        )
      }
      
    }

    // 2.渲染虚拟DOM到页面
    ReactDOM.render(<Login />, document.getElementById('test'))

  </script>
</body>

</html>